const express = require('express')

const app = express()

// 模板引擎
const nunjucks = require('nunjucks')
nunjucks.configure(`${__dirname}/views`, {
  autoescape: true
})

app.get('/oneLevel', (_, res) => {
  res.send(nunjucks.render('ajax一级封装.html'))
})

app.get('/twoLevel', (_, res) => {
  res.send(nunjucks.render('ajax二级封装.html'))
})

app.get('/threeLevel', (_, res) => {
  res.send(nunjucks.render('ajax三级封装.html'))
})

// 接口
app.get('/jquery', (req, res) => {
  const { id } = req.query
  res.send(id)
})

app.get('/json', (req, res) => {
  const { id } = req.query
  res.json({
    id
  })
})

app.listen(80, () => {
  console.log('express server running at http://127.0.0.1')
})